package com.epfresh.supplier.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.daimajia.swipe.SwipeLayout;
import com.epfresh.supplier.R;
import com.epfresh.supplier.adapter.CustomerDeliveryAdapter;
import com.epfresh.supplier.entity.DeliveryItem;
import com.epfresh.supplier.widget.BaseItemDecoration;
import com.epfresh.supplier.widget.RecyclerViewAdapter;
import com.epfresh.supplier.widget.RequestDeliveryActivity;
import java.util.ArrayList;

public class CustomerDeliveryActivity extends RequestDeliveryActivity implements RecyclerViewAdapter.OnItemClickListener {

    private LinearLayout mLlDelivery;
    private RecyclerView mDeliveryRv;
    private CustomerDeliveryAdapter mCustomerDeliveryAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer_delivery);

        initView();
        getDeliveryList(getIntent().getStringExtra("accountId"));
        initRv();
    }
    @Override
    protected View getToolBar() {
        return null;
    }

    private void initRv() {
        mDeliveryRv = (RecyclerView) findViewById(R.id.rv_delivery);
        mDeliveryRv.setLayoutManager(new LinearLayoutManager(this));
        mDeliveryRv.addItemDecoration(new BaseItemDecoration(this, R.drawable.shape_big_line));
        mCustomerDeliveryAdapter = new CustomerDeliveryAdapter(null);
        mDeliveryRv.setAdapter(mCustomerDeliveryAdapter);
    }

    private void initView() {
        mLlDelivery = (LinearLayout) findViewById(R.id.ll_delivery_nowhere);
        findViewById(R.id.back_ll).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    protected void updateUI(ArrayList<DeliveryItem> mDeliveryItem) {
        if (0 == mDeliveryItem.size()) {
            mLlDelivery.setVisibility(View.VISIBLE);
            mDeliveryRv.setVisibility(View.GONE);
        }else {
            mLlDelivery.setVisibility(View.GONE);
            mDeliveryRv.setVisibility(View.VISIBLE);
            mCustomerDeliveryAdapter.setData(mDeliveryItem);
            mCustomerDeliveryAdapter.setOnItemClickListener(this);
        }
    }

    @Override
    public void onItemClick(RecyclerView parent, View view, int position, SwipeLayout swipeLayout) {
        switch (parent.getId()) {
            case R.id.rv_delivery:
                switch (view.getId()) {
                    case R.id.ll_delivery:
                        //产品告知 收货地址之后有选择功能
                        break;
                }
        }
    }
}
